<?php
  //Buffer larger content areas like the main page content
  ob_start();
include("config.php");

   require_once("auth.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script>
function funhide()
{
document.getElementById('tc2').style.display="block";
document.getElementById('tc1').style.display="none";
}
</script>
<script type="text/javascript" src="js/compvalidator.js"></script>
<script>
var count=0;

function load(thediv, thefile) /* 2 parameters passed into here: the id of the div container and the name of the page to go to */
{  
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');  
    }
    xmlhttp.addEventListener("error", transferFailed, false);  
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById( thediv ).innerHTML = xmlhttp.responseText;
        }
    }  
 
   xmlhttp.open('GET', thefile, true);
    xmlhttp.send();
	    
}

function transferFailed(evt) {  
  alert("An error occurred while transferring the file.");  
}

function funchange(t)
{
window.location="computers.php?catname="+t;

}
function funchange1(t,id)
{
window.location="computers.php?catname="+t +"&id="+ id;

}

</script>

</head>
<body>
<?php 
if(isset($_REQUEST['id']))
{

$id=$_REQUEST['id'];
$data=mysql_query("select * from items where itemid='$id'");
$no=mysql_num_rows($data);
if($no!=0)
{
	while($row=mysql_fetch_assoc($data))
	{
?>

<form action="update_computers_submit.php" method="post" enctype="multipart/form-data" id="frmcomputers">
<div id="status"></div>
<table align="center">
<tr><td width="187">Main Category</td>
<td width="226"><select name="ddlmcategory" id="ddlmcategory" onchange="funchange1(this.value,'<?php echo $id;  ?>');">
						<?php
                        $data=mysql_query("select * from maincategories");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option <?php if((isset($_REQUEST['catname'])==$rec['maincatname'])|| ($row['maincatname']==$rec['maincatname'])) echo "selected='selected'"; ?>><?php echo $rec['maincatname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

      </select></td>
					<td width="99">Sub Category</td><td width="247"><select name="ddlscategory" id="ddlscategory">
						<?php
						if(isset($_REQUEST['catname']))
						{
						$cat=$_REQUEST['catname'];
						}
						else
						{
						$cat=$row['maincatname'];
						}
                        $data=mysql_query("select * from subcategory where maincatname='$cat'");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option   <?php if(($row['subcatname'])==$rec['subcatname']) echo "selected='selected'"; ?> ><?php echo $rec['subcatname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

                    </select></td>
					
</tr>
<tr>
<td width="187">Product Name<span style="color:#FF0000">*</span></td>
<td width="226"><input  type="text" name="txtprdname" id="txtprdname"  value="<?php echo $row['itemname']; ?>"></td>
<td>Cost<span style="color:#FF0000">*</span></td><td colspan="3"><input type="text" name="txtcost" id="txtcost" onkeypress="return numbersonly(event);" value="<?php echo $row['cost']; ?>"></td></tr>



<tr><td>brand<span style="color:#FF0000">*</span></td><td><select name="ddlbrand" id="ddlbrand">
						<?php
                        $data=mysql_query("select * from brands");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option <?php if($row['brand']==$rec['brandname']) echo "selected='selected'"; ?>><?php echo $rec['brandname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

                    </select></td>
                    <td>Model<span style="color:#FF0000">*</span></td>
                    <td><input type="text" name="txtmodel" id="txtmodel" value="<?php echo $row['model']; ?>"> </td></tr>
                    
                    

<tr>  </tr>

<tr><td valign="top" colspan="1">Available No of Product<span style="color:#FF0000">*</span></td><td colspan="3"><input type="text" value="<?php echo $rec['available']; ?>" name="avilable" id="avialble" onkeypress="return numbersonly(event);"/></td></tr>
<tr><td valign="top">Details<span style="color:#FF0000">*</span></td><td colspan="3"><textarea name="textdetails" id="textdetails" style="height:10em; width:35em;"> <?php echo $row['details']; ?></textarea></td></tr>


 <tr><td colspan="4">
	<div>
	
					<table  width="100%"id="tc1">
						  <tr><td width="32%"> <input type="hidden"  value="<?php echo $row['imagepath'];?>"  name="txtoldtechname"/><img src="<?php
											
						  echo  $row['imagepath'];?>" width="100px" height="100px" /><br /> <input type="hidden" value=" <?php $xx=$row['picture'];
						    $x=explode ('/',$xx);	
							echo $rec['picture']; ?>" id="pic" /></td>
						  <td width="68%" colspan="2">&nbsp;&nbsp;
											Do you want to Replace the File<br>
											&nbsp;&nbsp;<a href="#" onClick="funhide();"> Click Here To Upload Other One</a>						</td>
						  </tr>
				  </table>
				  <table id="tc2" style="display:none" width="100%">							<tr>
							<td width="186"  class="classalign">Picture<span style="color:#FF0000">*</span>:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
					<td width="348"><input type="file" name="filePicture" id="filePicture"><input type="hidden" name="ivalue" value="3" id="someVar"/></td>
							</tr>
				</table>
</div>
</td></tr>

<tr><td colspan="3" align="right"><input type="hidden" value="<?php echo $id; ?>"  name="id" />
<input type="button" name="btnaddcomputers" id="btnaddcomputers" value="update Product" onclick="validateForm2('update_computers_submit.php','frmcomputers','thediv','<img src=\'pleasewait.gif\'>');" /></td></tr>
</table>

</form>



<?php

	}}
}
else
{
	?>
<form action="computers_submit.php" method="post" enctype="multipart/form-data" id="frmcomputers">
<div id="status"></div>
<table align="center">
<tr><td width="181">Main Category</td>
<td width="222"><select name="ddlmcategory" id="ddlmcategory" onchange="funchange(this.value);">
						<?php
                        $data=mysql_query("select * from maincategories");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option <?php if(isset($_REQUEST['catname']))
						{if($_REQUEST['catname']==$rec['maincatname']) {echo "selected='selected'";  }}?>><?php echo $rec['maincatname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

      </select></td>
					<td width="99">Sub Category</td><td width="247"><select name="ddlscategory" id="ddlscategory">
						<?php
						if(isset($_REQUEST['catname']))
						{
						$cat=$_REQUEST['catname'];
						}
						else 
						{								$cat='computers';
			}
                        $data=mysql_query("select * from subcategory where maincatname='$cat'");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option><?php echo $rec['subcatname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

                    </select></td>
					
</tr>


<tr><td width="181">Product Name<span style="color:#FF0000">*</span></td>
<td width="222"><input  type="text" name="txtprdname" id="txtprdname"></td>
<td>Cost<span style="color:#FF0000">*</span></td><td colspan="3"><input type="text" name="txtcost" id="txtcost" onkeypress="return numbersonly(event);"></td>
</tr>
<tr><td>brand<span style="color:#FF0000">*</span></td><td><select name="ddlbrand" id="ddlbrand">
						<?php
                        $data=mysql_query("select * from brands");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option><?php echo $rec['brandname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

                    </select></td>
  <td>Model<span style="color:#FF0000">*</span></td><td><input type="text" name="txtmodel" id="txtmodel"> </td></tr>
<tr><td valign="top" colspan="1">Available No of Product<span style="color:#FF0000">*</span></td><td colspan="3"><input type="text" name="avilable" id="avialble" onkeypress="return numbersonly(event);"/></td></tr>

<tr><td valign="top">Details<span style="color:#FF0000">*</span></td><td colspan="3"><textarea name="textdetails" id="textdetails" style="height:10em; width:35em;"></textarea></td></tr>
<tr><td>Image<span style="color:#FF0000">*</span></td><td colspan="3"><input type="hidden"  id="pic" /><input type="file" id="filePicture" name="filePicture" /><input type="hidden" name="ivalue" value="3" id="someVar"/>
</td></tr>
<tr><td colspan="3" align="right"><input type="button" name="btnaddcomputers" id="btnaddcomputers" value="Add Product" onclick="validateForm2('computers_submit.php','frmcomputers','thediv','<img src=\'pleasewait.gif\'>');" /></td></tr>
</table>

</form>
<?php
}
?>
</body>
</html>
 <?php
  //Assign all Page Specific variables
  $pagemaincontent = ob_get_contents();
  ob_end_clean();
  $pagetitle = "Computers";
  //Apply the template
  include("master.php");
?>    